using ComprehensiveSystem.Auth.HttpContextUser;
using ComprehensiveSystem.Caching.Manual;
using ComprehensiveSystem.Configuration;
using ComprehensiveSystem.IRepository;
using ComprehensiveSystem.IRepository.UnitOfWork;
using ComprehensiveSystem.Model.Entities;
using SqlSugar;


namespace ComprehensiveSystem.Repository
{
    public class PatientRepository : BaseRepository<PatientEntity>, IPatientRepository
    {
        private readonly IUnitOfWork _unitOfWork;
        private readonly IHttpContextUser _user;
        public PatientRepository(IUnitOfWork unitOfWork, IHttpContextUser user) : base(unitOfWork)
        {
            _unitOfWork = unitOfWork;
            _user = user;
        }
        #region 获取缓存的所有数据==========================================================
        /// <summary>
        /// 获取缓存的所有数据
        /// </summary>
        /// <returns></returns>
        public async Task<List<PatientEntity>> GetCaChe()
        {
            var cache = ManualDataCache.Instance.Get<List<PatientEntity>>(GlobalConstVars.CachePatient);
            if (cache != null)
            {
                return cache;
            }
            return await UpdateCaChe();
        }
        /// <summary>
        /// 更新cache
        /// </summary>
        public async Task<List<PatientEntity>> UpdateCaChe()
        {
            var list = await DbClient.Queryable<PatientEntity>().With(SqlWith.NoLock).ToListAsync();
            ManualDataCache.Instance.Set(GlobalConstVars.CachePatient, list);
            return list;
        }
        #endregion
    }
}
